home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
VideoFolder 1.0a
/
Source
/
VideoFolderDocument.cp
< prev
next >
Wrap
Text File
|
1996-06-21
|
7KB
|
246 lines
#include "VideoFolderDocument.h"
#include "FSSpecPane.h"
#include "SequenceGrabberPane.h"
#include "VideoFolderWindow.h"
const ResIDT window_Sample = 1; // EXAMPLE
VideoFolderDocument::VideoFolderDocument() :
mVideoFolderWindow ( nil ),
mFile ( nil )
{
mVideoFolderWindow = dynamic_cast<VideoFolderWindow*> ( LWindow::CreateWindow(window_Sample, this) );
Assert_ ( mVideoFolderWindow );
mVideoFolderWindow->Show();
}
VideoFolderDocument::VideoFolderDocument ( LCommander* inSuper, const FSSpec* inSpec ) :
mVideoFolderWindow ( nil ),
mFile ( nil )
{
mVideoFolderWindow = dynamic_cast<VideoFolderWindow*> ( LWindow::CreateWindow(window_Sample, this) );
Assert_ ( mVideoFolderWindow );
if ( inSpec )
OpenFile ( *inSpec );
else
NameNewDoc();
mVideoFolderWindow->Show();
}
VideoFolderDocument::~VideoFolderDocument ( )
{
}
Boolean
VideoFolderDocument::AllowSubRemoval(
LCommander *inSub)
{
if (inSub == mVideoFolderWindow) {
// Check if the current AppleEvent is a "close" event
// sent to the Window. If so, we handle it as if the
// "close" event were sent to the Document
AppleEvent currentEvent;
DescType theType;
DescType theAttr = typeNull;
Size theSize;
::AEGetTheCurrentEvent(¤tEvent);
if (currentEvent.descriptorType != typeNull) {
::AEGetAttributePtr(¤tEvent, keyEventClassAttr,
typeType, &theType, &theAttr, sizeof(DescType),
&theSize);
if (theAttr == kAECoreSuite) {
::AEGetAttributePtr(¤tEvent, keyEventIDAttr,
typeType, &theType, &theAttr, sizeof(DescType),
&theSize);
if (theAttr == kAEClose) {
DoAEClose(currentEvent);
return false;
}
}
}
AttemptClose(true); // A non-AppleEvent close
return false;
} else {
return true;
}
}
// ---------------------------------------------------------------------------
// • GetDescriptor
// ---------------------------------------------------------------------------
// Pass back the name of a Document
StringPtr
VideoFolderDocument::GetDescriptor(
Str255 outDescriptor) const
{
if ((mFile != nil) && mIsSpecified) {
FSSpec fileSpec; // Document name is same as its File
mFile->GetSpecifier(fileSpec);
LString::CopyPStr(fileSpec.name, outDescriptor);
} else if (mVideoFolderWindow != nil) { // No File, use name of its Window
mVideoFolderWindow->GetDescriptor(outDescriptor);
} else { // No File and No Window
outDescriptor[0] = 0; // Document name is empty string
}
return outDescriptor;
}
void
VideoFolderDocument::NameNewDoc()
{
// Setup the window title. Start with the default title.
LStr255 theTitle( "\pUntitled" );
// Find the first available title. We could also check the window
// pane id if we wanted to make sure we didn't collide with other
// window types.
Int32 theNumber = 0;
while ( UWindows::FindNamedWindow( theTitle ) != nil ) {
// An existing window has the current name
// Increment counter and try again.
++theNumber;
theTitle = "\pUntitled ";
theTitle += (LStr255) theNumber;
}
// Finally, set window title.
mVideoFolderWindow->SetDescriptor( theTitle );
}
void VideoFolderDocument::OpenFile ( const FSSpec& inFileSpec )
{
Try_ {
// Create a new file object.
mFile = new LFileStream ( inFileSpec );
// Open the data fork.
mFile->OpenDataFork( fsRdWrPerm );
// Set window title to the name of the file.
mVideoFolderWindow->SetDescriptor( inFileSpec.name );
unsigned long signature;
mFile->ReadData ( & signature, sizeof( signature ) );
ThrowIfNot_ ( signature == 'KSS!' );
unsigned long version;
mFile->WriteData ( & version, sizeof( version ) );
ThrowIfNot_ ( version == 1 );
unsigned long interval = mVideoFolderWindow->GetUpdateInterval();
mFile->ReadData ( & interval, sizeof ( interval ) );
mVideoFolderWindow->SetUpdateInterval ( interval );
unsigned long liveUpdate = true;
LPane* liveUpdatePane = dynamic_cast<LPane*> ( mVideoFolderWindow->FindPaneByID ( 'LIVE' ) );
mFile->ReadData ( & liveUpdate, sizeof( liveUpdate ) );
if ( liveUpdatePane )
liveUpdatePane->SetValue( liveUpdate );
FSSpec spec = { 0, 0, "\p" };
FSSpecPane* destFSSpecPane = dynamic_cast<FSSpecPane*> ( mVideoFolderWindow->FindPaneByID ( 'DSTF' ) );
mFile->ReadData ( & spec, sizeof( spec ) );
if ( destFSSpecPane )
destFSSpecPane->SetFSSpec ( spec );
SequenceGrabberPane* grabberPane = dynamic_cast<SequenceGrabberPane*> ( mVideoFolderWindow->FindPaneByID ( 'sgrb' ) );
ThrowIfNil_( grabberPane );
Handle configurationHandle = nil;
mFile->ReadHandle ( configurationHandle );
grabberPane->SetConfiguration ( configurationHandle );
DisposeHandle ( configurationHandle );
mFile->CloseDataFork();
// Flag that document has an associated file.
mIsSpecified = true;
} Catch_( inErr ) {
// Cleanup and rethrow the error.
delete this;
Throw_( inErr );
} EndCatch_
}
void VideoFolderDocument::DoAESave(FSSpec &inFileSpec, OSType inFileType)
{
// Delete the existing file object.
delete mFile;
// Make a new file object.
mFile = new LFileStream( inFileSpec );
// Get the proper file type.
OSType theFileType = 'VFol';
if ( inFileType != fileType_Default ) theFileType = inFileType;
// Make new file on disk (we'll use
// SimpleText's creator for this example).
mFile->CreateNewDataFile( 'ttxt', theFileType );
// Write out the data.
DoSave();
// Change window title to reflect the new name.
mVideoFolderWindow->SetDescriptor( inFileSpec.name );
// Document now has a specified file.
mIsSpecified = true;
}
void VideoFolderDocument::DoSave ( )
{
ThrowIfNil_( mVideoFolderWindow );
// Open the data fork.
mFile->OpenDataFork( fsRdWrPerm );
unsigned long signature = 'KSS!';
mFile->WriteData ( & signature, sizeof( signature ) );
unsigned long version = 1;
mFile->WriteData ( & version, sizeof( version ) );
unsigned long interval = mVideoFolderWindow->GetUpdateInterval();
mFile->WriteData ( & interval, sizeof ( interval ) );
unsigned long liveUpdate = true;
LPane* liveUpdatePane = dynamic_cast<LPane*> ( mVideoFolderWindow->FindPaneByID ( 'LIVE' ) );
if ( liveUpdatePane )
liveUpdate = liveUpdatePane->GetValue() != 0;
mFile->WriteData ( & liveUpdate, sizeof( liveUpdate ) );
FSSpec spec = { 0, 0, "\p" };
FSSpecPane* destFSSpecPane = dynamic_cast<FSSpecPane*> ( mVideoFolderWindow->FindPaneByID ( 'DSTF' ) );
if ( destFSSpecPane )
destFSSpecPane->GetFSSpec ( spec );
mFile->WriteData ( & spec, sizeof( spec ) );
SequenceGrabberPane* grabberPane = dynamic_cast<SequenceGrabberPane*> ( mVideoFolderWindow->FindPaneByID ( 'sgrb' ) );
ThrowIfNil_( grabberPane );
Handle configurationHandle = grabberPane->GetConfiguration ( );
mFile->WriteHandle ( configurationHandle );
DisposeHandle ( configurationHandle );
// Close the data fork.
mFile->CloseDataFork();
}